package Hxw3DEngine.core.component.animation
{
	import Hxw3DEngine.core.Resource.animation.VertexAnimationClip;
	import Hxw3DEngine.core.component.renderer.MeshRenderer;
	
	import flash.utils.Dictionary;
	
	//顶点动画管理器
	public class VertexAnimation extends Animation
	{
		//动画源数据没有处理过的
		public var data:Dictionary;
		
		//数据处理是为了方便可以用语法.到想要的属性  要不然一个animationNode就可以完成所有的动画数据处理因为数据类型是*可以上下转换
		public function VertexAnimation(_data:Dictionary, _targetStreamComponents:int)
		{
			super();
			delay = 300;
			
			var key:String
			for (key in _data)
			{
				var animationNode:VertexAnimationClip = new VertexAnimationClip(key, _data[key], _targetStreamComponents);
				animationNode.name = key;
				super.addClip(animationNode);
			}
		}
		
		//运行时更改网格数据
		override public function run():void
		{
			var meshRenderer:MeshRenderer = _object3d.getComponent(MeshRenderer) as MeshRenderer;
			if (meshRenderer != null)
			{
				meshRenderer.geometry.UpdateStream(VertexAnimationClip(currentAnimation).targetStreamComponents, getCurrentFrameData());
			}
		}
	}
}